package com.jyw.business.obstacles.domain.dto.web;

import com.jyw.business.obstacles.domain.ObsOrderSend;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.system.domain.vo.SysOrderAutoDispatchVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;

/**
 * @author 沈峻
 * @ClassName allocateDto
 * @Description 派单请求实体
 * @Date 2023/9/8 11:09
 **/
@Data
@ApiModel("派单请求实体")
@NoArgsConstructor
public class AllocateDto extends BaseOrderDto{

    @ApiModelProperty(value = "派单对象类型", required = true)
    @NotNull(message = "派单对象类型不能为空")
    private Integer sendObjType;

    @ApiModelProperty(value = "派单对象标识", required = true)
    @NotNull(message = "派单对象标识为空")
    private Long sendObjId;

    @ApiModelProperty("派单所属小组(派单给小组人员时需要携带小组标识)")
    private Long sendTeam;

    public AllocateDto(SysOrderAutoDispatchVo vo) {
        setSendObjType(vo.getSendType());
        if(vo.getSendType()==1){
            setSendObjId(vo.getSendUser());
            setSendTeam(vo.getSendTeam());
        }else if(vo.getSendType()==2){
            setSendObjId(vo.getSendTeam());
        }
    }

    public ObsOrderSend buildSend(){
        ObsOrderSend send = new ObsOrderSend();
        send.setOrderNum(getOrderNum());
        send.setSendType(getSendObjType());
        switch (getSendObjType()){
            case 1:
                send.setSendUser(getSendObjId());
                break;
            case 2:
                send.setSendTeam(getSendObjId());
                break;
            case 3:
                send.setSendDept(getSendObjId());
                break;
        }
        send.setCreateUser(SecurityUtils.getUserId());
        send.setCreateTime(DateUtils.getNowDate());
        send.setType(1);
        return send;
    }
}
